home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Interapplication Communication / IPCLister / IPCListCode.c next >
Encoding:
C/C++ Source or Header  |  1993-01-18  |  7.7 KB  |  196 lines  |  [TEXT/MPS ]

  1. /* IPCList code by Jim Luther, converted to C by Me <TR> */
  2. /* I've left a lot of the Pascal definitions, comments, and some code */
  3. /* in this (in comments) so you Pascal-heads can see it better */
  4.  
  5. #include <Types.h>
  6. #include <memory.h>
  7. #include <Packages.h>
  8. #include <Errors.h>
  9. #include <quickdraw.h>
  10. #include <fonts.h>
  11. #include <dialogs.h>
  12. #include <windows.h>
  13. #include <menus.h>
  14. #include <events.h>
  15. #include <OSEvents.h>
  16. #include <Desk.h>
  17. #include <diskinit.h>
  18. #include <OSUtils.h>
  19. #include <resources.h>
  20. #include <toolutils.h>
  21. #include <AppleEvents.h>
  22. #include <EPPC.h>
  23. #include <GestaltEqu.h>
  24. #include <PPCToolbox.h> 
  25. #include <Processes.h>
  26. #include <Balloons.h>
  27. #include <ALiases.h>
  28. #include <Processes.h>
  29. #include <StandardFile.h>
  30. #include <Folders.h>
  31. #include <AppleTalk.h> 
  32.  
  33.  
  34. #define MaxTuples  100
  35. #define  MaxPorts  100
  36. typedef unsigned char Tuple[104];
  37.  
  38. /*
  39. TYPE
  40. Tuple = PACKED ARRAY[1..104] OF Char;
  41. { an AddrBlock (4 bytes), a one byte enumerator, and an EntityName (99 bytes) }
  42. */
  43.  
  44. Tuple myRetBuff[100];                                       /*  myRetBuff: ARRAY[1..MaxTuples] OF Tuple;{for NBP Lookup} */
  45. MPPParamBlock paramblk;                                     /*  paramblk: MPPParamBlock; */
  46. EntityName myEntityName;                                    /* myEntityName: EntityName; */
  47. AddrBlock myAddrBlock;                                      /* myAddrBlock: AddrBlock; */
  48. short i, j;                                                 /* i, j: integer; */
  49. short gCount;                                               /*  gCount: integer; */
  50. PortInfoRec gPortInfoBuffer[100];                           /*  gPortInfoBuffer: ARRAY[1..MaxPorts] OF PortInfoRec; */
  51. XPPParamBlock xppParamblk;                                  /*  xppParamblk: XPPParamBlock; */
  52. Str255 zoneName;                                            /*  zoneName: Str255; */
  53.  
  54. OSErr gErr;                                                 /*  gErr: OSErr; */
  55.  
  56.  
  57.  
  58. #if 0
  59. /* Jim's orignal comment */
  60. {*********************************************************************}
  61. {*}
  62. {*  IPCListPorts:  Return a list of PortInfoRecs in the buffer pointed}
  63. {*            to by thePortInfoBufferPtr.  The actual number of}
  64. {*            PortInfoRecs returned will be in theActualCount.}
  65. {*  }
  66. {*  myIPCListPorts}
  67. {*    The function returns with any errors from IPCListPorts.}
  68. {*  theStartIndex}
  69. {*    The index into the port entry list.  To start at the}
  70. {*    beginning, use 0.}
  71. {*  theRequestCount}
  72. {*    The maximum number of portInfoRecs that can be returned.  Make}
  73. {*    sure the buffer pointed to by thePortInfoBufferPtr is at least}
  74. {*    SizeOf(PortInfoRec) * theRequestCount.}
  75. {*  theActualCount}
  76. {*    This returns the actual number of PortInfoRecs returned in }
  77. {*    the buffer pointed to by thePortInfoBufferPtr.}
  78. {*  theObjStr}
  79. {*    The NBP object to be used in the LocationNameRec.}
  80. {*  theZoneStr}
  81. {*    The NBP zone to be used in the LocationNameRec.}
  82. {*  thePortInfoBufferPtr}
  83. {*    This points to an array of PortInfoRecs.  IPCListPorts fills it}
  84. {*    with a list of ports matching thePPCPortRec at the location}
  85. {*    specified by theLocationNameRec.  The size of this array must}
  86. {*    be at least SizeOf(PortInfoRec) * theRequestCount.}
  87. {*  theIPCListPortsPBRec}
  88. {*    The parameter block passed to the IPCListPorts call.  The}
  89. {*    startIndex, requestCount, portName, locationName, and bufferPtr}
  90. {*    fields must be supplied.  If the IPCListPorts call is made}
  91. {*    asynchronously, the ioCompletion field must be supplied.}
  92. {*  thePPCPortRec}
  93. {*    IPCListPorts will only list ports that match the PPC port name}
  94. {*    supplied.  An equal sign (=) can be used for the name and/or}
  95. {*    portTypeStr as a wildcard to match all ports names.}
  96. {*  theLocationNameRec}
  97. {*    IPCListPorts will list the ports at this location.  The}
  98. {*    NBP object and NBP zone must be chosen from the lists returned}
  99. {*    by NBPLookup and GetZoneList.  The NBP type can be application}
  100. {*    specific.  If you don't supply your own NBP type, you should}
  101. {*    use "PPCToolBox" for the NBP type string.  The}
  102. {*    locationKindSelector field must be set to either ppcNoLocation}
  103. {*    (which specifies the local computer) or ppcNBPLocation (which}
  104. {*    specifies the complete NBP entity).}
  105. {*....................................................................}
  106.  
  107. #endif
  108.  
  109.  
  110. OSErr myIPCListPorts(short theStartIndex, short theRequestCount, short *theActualCount, Str32 theObjStr, Str32 theZoneStr,
  111.                      PortInfoArrayPtr thePortInfoBufferPtr)
  112. {
  113.     
  114.     OSErr myErr;
  115.     IPCListPortsPBRec theIPCListPortsPBRec;
  116.     PPCPortRec thePPCPortRec;
  117.     LocationNameRec theLocationNameRec;
  118.     Str32 ppcWord = "\pPPCToolBox";
  119.     /* List all PPC ports at the specified location */
  120.     thePPCPortRec.nameScript = 0;
  121.     thePPCPortRec.name[0] = 1;
  122.     thePPCPortRec.name[1] = '=';                            /* match all names */
  123.     thePPCPortRec.portKindSelector = ppcByString;
  124.     thePPCPortRec.u.portTypeStr[0] = 1;                     /* match all names */
  125.     thePPCPortRec.u.portTypeStr[1] = '=';                   /* match all names */
  126.     
  127.     theLocationNameRec.locationKindSelector = ppcNBPLocation; /* using an NBP construct */
  128.     /* Move the passed infomation into the location name */
  129.     BlockMove((Ptr)&theObjStr[0], (Ptr)&theLocationNameRec.u.nbpEntity.objStr, theObjStr[0] + 1);
  130.     BlockMove((Ptr)&ppcWord[0], (Ptr)&theLocationNameRec.u.nbpEntity.typeStr, ppcWord[0] + 1);
  131.     BlockMove((Ptr)&theZoneStr[0], (Ptr)&theLocationNameRec.u.nbpEntity.zoneStr, theZoneStr[0] + 1);
  132.     /* last parameters */
  133.     theIPCListPortsPBRec.startIndex = theStartIndex;
  134.     theIPCListPortsPBRec.requestCount = theRequestCount;
  135.     theIPCListPortsPBRec.portName = &thePPCPortRec;
  136.     theIPCListPortsPBRec.locationName = &theLocationNameRec;
  137.     theIPCListPortsPBRec.bufferPtr = thePortInfoBufferPtr;
  138.     
  139.     /* Call IPCListPorts synchronously */
  140.     myErr = IPCListPortsSync(&theIPCListPortsPBRec);
  141.     
  142.     *theActualCount = theIPCListPortsPBRec.actualCount;
  143.     return(myErr);
  144. }
  145.  
  146. OSErr GetAllPPCAbleMachines(MPPParamBlock *paramblk)
  147. {
  148.     /* This used to be the main section of the code.  Now I call it to fill in */
  149.     /* my list */
  150.     xppParamblk.XCALL.csCode = xCall;
  151.     xppParamblk.XCALL.xppSubCode = zipGetMyZone;
  152.     xppParamblk.XCALL.xppTimeout = 3;
  153.     xppParamblk.XCALL.xppRetry = 4;
  154.     xppParamblk.XCALL.zipBuffPtr = &zoneName;
  155.     xppParamblk.XCALL.zipInfoField[1] = 0;
  156.     gErr = GetMyZone(&xppParamblk, false);
  157.     
  158.     if (gErr != noErr) {
  159.         DebugStr("\pZone fail");
  160.         zoneName[0] = 1;
  161.         zoneName[1] = '*';
  162.     }
  163.     /* noZone is '*' */
  164.     
  165.     
  166.     NBPSetEntity((Ptr)&myEntityName, "\p=", "\pPPCToolBox", zoneName);
  167.     
  168.     paramblk->NBP.interval = 5;
  169.     paramblk->NBP.count = 5;
  170.     paramblk->NBP.NBPPtrs.entityPtr = (Ptr)&myEntityName;
  171.     paramblk->NBP.parm.Lookup.retBuffPtr = (Ptr)&myRetBuff;
  172.     paramblk->NBP.parm.Lookup.retBuffSize = sizeof(myRetBuff);
  173.     paramblk->NBP.parm.Lookup.maxToGet = MaxTuples;
  174.     paramblk->NBP.parm.Lookup.numGotten = 0;
  175.     gErr = PLookupName(paramblk, false);
  176.     
  177. }
  178.  
  179. OSErr GetPortsOnMachine(MPPParamBlock *paramblk)
  180. {
  181.     if (paramblk->NBP.parm.Lookup.numGotten > 0) {
  182.         for (i = 1; i < paramblk->NBP.parm.Lookup.numGotten; i++) {
  183.             //  {extract the NBP name}
  184.             gErr = NBPExtract((Ptr)&myRetBuff, paramblk->NBP.parm.Lookup.numGotten, i, &myEntityName, &myAddrBlock);
  185.             
  186.             //  writeln('Getting ports on ', myEntityName.objStr);
  187.             //  {get the list of PPC ports}
  188.             gErr = myIPCListPorts(0, MaxPorts, &gCount, myEntityName.objStr, myEntityName.zoneStr, &gPortInfoBuffer);
  189.             
  190.             //  FOR j = 1 TO gCount DO
  191.             //  Writeln('  ', gPortInfoBuffer[j].name.name);
  192.             
  193.         }
  194.     }
  195. }
  196.